/*     */ package com.zimbra.cs.account.ldap;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Group;
/*     */ import com.zimbra.cs.ldap.IAttributes;
/*     */ import com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor;
/*     */ import com.zimbra.cs.ldap.ZLdapFilterFactory;
/*     */ import java.util.Collections;
/*     */ import java.util.HashSet;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Groups
/*     */ {
/*     */   private LdapProv mProv;
/*  36 */   private Set<String> mAllDLs = null;
/*     */   
/*     */   private static class GetAllDLsVisitor extends SearchLdapOptions.SearchLdapVisitor {
/*  39 */     Set<String> allDLs = new HashSet();
/*     */     
/*     */     public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs)
/*     */     {
/*  43 */       Object addrs = attrs.get("mail");
/*  44 */       if ((addrs instanceof String)) {
/*  45 */         this.allDLs.add(((String)addrs).toLowerCase());
/*  46 */       } else if ((addrs instanceof String[])) {
/*  47 */         for (String addr : (String[])addrs)
/*  48 */           this.allDLs.add(addr.toLowerCase());
/*     */       }
/*     */     }
/*     */     
/*     */     private Set<String> getResult() {
/*  53 */       return this.allDLs;
/*     */     }
/*     */   }
/*     */   
/*     */   public Groups(LdapProv prov) {
/*  58 */     this.mProv = prov;
/*     */   }
/*     */   
/*     */   private synchronized Set<String> getAllDLs() throws ServiceException {
/*  62 */     if (this.mAllDLs == null) {
/*     */       try {
/*  64 */         GetAllDLsVisitor visitor = new GetAllDLsVisitor(null);
/*  65 */         this.mProv.searchLdapOnReplica(this.mProv.getDIT().mailBranchBaseDN(), ZLdapFilterFactory.getInstance().allGroups(), new String[] { "mail" }, visitor);
/*     */         
/*     */ 
/*     */ 
/*     */ 
/*  70 */         this.mAllDLs = Collections.synchronizedSet(visitor.getResult());
/*     */       } catch (ServiceException e) {
/*  72 */         ZimbraLog.account.error("unable to get all DLs", e);
/*     */       }
/*     */     }
/*  75 */     return this.mAllDLs;
/*     */   }
/*     */   
/*     */ 
/*  79 */   public synchronized void clear() { this.mAllDLs = null; }
/*     */   
/*     */   public void addGroup(Group dl) {
/*     */     Set<String> allGroups;
/*     */     try {
/*  84 */       allGroups = getAllDLs();
/*  85 */       for (String email : dl.getMultiAttrSet("mail")) {
/*  86 */         allGroups.add(email.toLowerCase());
/*     */       }
/*     */     }
/*     */     catch (ServiceException e) {}
/*     */   }
/*     */   
/*     */   public void removeGroup(Set<String> addrs) {
/*     */     Set<String> allGroups;
/*     */     try {
/*  95 */       allGroups = getAllDLs();
/*  96 */       for (String addr : addrs) {
/*  97 */         allGroups.remove(addr.toLowerCase());
/*     */       }
/*     */     }
/*     */     catch (ServiceException e) {}
/*     */   }
/*     */   
/*     */   public void removeGroup(String addr)
/*     */   {
/*     */     try {
/* 106 */       Set<String> allGroups = getAllDLs();
/* 107 */       allGroups.remove(addr.toLowerCase());
/*     */     }
/*     */     catch (ServiceException e) {}
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean isGroup(String addr)
/*     */   {
/* 119 */     boolean isGroup = false;
/*     */     try {
/* 121 */       isGroup = getAllDLs().contains(addr.toLowerCase());
/*     */     }
/*     */     catch (ServiceException e) {
/* 124 */       ZimbraLog.account.warn("unable to determine if address " + addr + " is a DL", e);
/*     */     }
/* 126 */     ZimbraLog.account.debug("address " + addr + " isGroup=" + isGroup);
/* 127 */     return isGroup;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/Groups.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */